package com.learning.jquizenglish.screen.learningfeed;

import java.util.ArrayList;

import android.app.Activity;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.learning.jquizenglish.R;
import com.learning.jquizenglish.common.adapter.BaseQuizAnswerAdapter;
import com.learning.jquizenglish.model.AnswerModel;
import com.learning.jquizenglish.utility.CommonUtils;
import com.learning.jquizenglish.widget.ViewHolder;

public class LearningFeedChildAdapter extends BaseQuizAnswerAdapter{

	private String[] mAnswerTitle = {"A","B","C","D","E","F"};
	
	public LearningFeedChildAdapter(Activity activity,ArrayList<AnswerModel> datas) {
		super(activity, datas);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if (row == null) {
			row = LayoutInflater.from(mActivity).inflate(R.layout.learning_feed_answer_item, parent,false);
		}
		TextView tvTitle = ViewHolder.get(row, R.id.tvTitle);
		TextView tvAnswer = ViewHolder.get(row, R.id.tvContent);
		AnswerModel model = getItem(position);
		if (model!=null) {
			tvAnswer.setText(model.title);
			if(isAnswered){
				if (model.isChoise) {
					tvTitle.setText(mAnswerTitle[position]+". ");
					if (model.is_correct.trim().equals("1")) {
						tvAnswer.setText(Html.fromHtml(CommonUtils.additionCorrectAtTheEnd(model.title)));
					}else{
						tvAnswer.setText(Html.fromHtml(CommonUtils.additionWrongAtTheEnd(model.title)));
					}
				}else{
					tvTitle.setText(mAnswerTitle[position]+". ");
					if (model.is_correct.trim().equals("1")) {
						tvAnswer.setText(Html.fromHtml(CommonUtils.additionCorrectAtTheEnd(model.title)));
					}
				}
			}else{
				tvTitle.setText(mAnswerTitle[position]+". ");
			}
		}
		return row;
	}

}
